//
//  LPopChangView.m
//  GardenGaugeEcg
//
//  Created by 刘映雄 on 2016/12/16.
//  Copyright © 2016年 刘映雄. All rights reserved.
//

//主题颜色
#define MAINCOLOR SPCOLOR(89,199,103,1)

#import "LPopChangView.h"

@interface LPopChangView ()

@property (nonatomic,strong) UIView *bgView;
@property (nonatomic,strong) UILabel *nameLabel;

@end

@implementation LPopChangView

- (instancetype)initWithFrame:(CGRect)frame AndTitle:(NSString *)title type:(UIKeyboardType)type {
    if (self == [super initWithFrame:frame]) {
        
        self.backgroundColor = RGBColor(163, 163, 163, 0.4);
        self.layer.cornerRadius = 10;
        self.nameLabel.text = title;
        self.textField.placeholder = title;
        self.textField.keyboardType = type;
        
        [self addSubview:self.bgView];
        [self.bgView addSubview:self.nameLabel];
        [self.bgView addSubview:self.textField];
        
        [self changeUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame AndTitle:(NSString *)title Message:(NSString *)message {
    if (self == [super initWithFrame:frame]) {
        self.backgroundColor = RGBColor(163, 163, 163, 0.4);
        self.nameLabel.text = title;
        self.textField.text = message;
        
        [self addSubview:self.bgView];
        [self.bgView addSubview:self.nameLabel];
        [self.bgView addSubview:self.textField];
        
        self.textField.userInteractionEnabled = NO;
        self.textField.layer.borderWidth = 0;
        
        [self changeUI];
    }
    return self;
}

- (void)changeUI {
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(20 * xsIZE);
        make.centerY.equalTo(self.mas_centerY).offset(0);
        make.size.sizeOffset(CGSizeMake(SCREEN_Width - 40 * xsIZE, 120 * ysIZE));
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(0);
        make.top.equalTo(self.bgView.mas_top).offset(0);
        make.size.sizeOffset(CGSizeMake(SCREEN_Width - 40 * xsIZE, 30 * ysIZE));
    }];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(25 * xsIZE);
        make.centerY.equalTo(self.bgView.mas_centerY).offset(0);
        make.size.sizeOffset(CGSizeMake(SCREEN_Width - 90 * xsIZE, 30 * ysIZE));
    }];
    
    _cancel = [UIButton buttonWithType:UIButtonTypeCustom];
    [_cancel setTitle:@"取消" forState:UIControlStateNormal];
    [_cancel setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [_cancel addTarget:self action:@selector(LclickCancel) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:_cancel];
    
    _sure = [UIButton buttonWithType:UIButtonTypeCustom];
    [_sure setTitle:@"确认" forState:UIControlStateNormal];
    [_sure setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_sure addTarget:self action:@selector(LclickSure) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:_sure];
    
    [_sure mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.bgView.mas_bottom).offset(-5 * ysIZE);
        make.right.equalTo(self.bgView.mas_right).offset(-5 * xsIZE);
        make.size.sizeOffset(CGSizeMake(40 * xsIZE, 20 * ysIZE));
    }];
    
    [_cancel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sure.mas_top).offset(0);
        make.right.equalTo(self.sure.mas_left).offset(-25 * xsIZE);
        make.size.sizeOffset(CGSizeMake(40 * xsIZE, 20 * ysIZE));
    }];
    
}

- (void)LclickCancel {
    [self removeFromSuperview];
}

- (void)LclickSure {
   // [self.delegate LPopChangView:self];
//    !self.InputContentBlock?:self.InputContentBlock(self.textField.text);
//    
    
    if (self.InputContentBlock) {
        self.InputContentBlock(self.textField.text);
    };
    
    
}

#pragma mark -> 懒加载
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.layer.cornerRadius = 10;
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.textAlignment = NSTextAlignmentCenter;
        _nameLabel.font = NEWFONT(16);
    }
    return _nameLabel;
}

- (UITextField *)textField {
    if (!_textField) {
        _textField = [[UITextField alloc] init];
        _textField.textAlignment = NSTextAlignmentLeft;
        _textField.font = NEWFONT(14);
        _textField.layer.borderWidth = 1.0f;
        _textField.layer.cornerRadius = 5;
        _textField.layer.borderColor = KHGreenColor.CGColor;
        _textField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 3 * xsIZE, 30 * ysIZE)];
        _textField.leftViewMode = UITextFieldViewModeAlways;
    }
    return _textField;
}

@end
